import sys
import os
import zipfile

if (len(sys.argv) != 3):
	print "Extract.py - Usage: extract.py zipfile.zip destinationfolder"
	sys.exit(-1)

def Deltree(folder):
	if (os.path.exists(folder)):
		for the_file in os.listdir(folder):
			file_path = os.path.join(folder)
			try:
				os.unlink(file_path)
			except Exception, e:
				continue

try:
	Deltree(sys.argv[2])
	with zipfile.ZipFile(sys.argv[1], 'r') as bioszip:
		bioszip.extractall(sys.argv[2])
	
except Exception, e:
	Deltree(sys.argv[2])
	print "Extract.py - Erro extraindo arquivos."
	print e
	sys.exit(-1)
	
sys.exit(0)

